import {createApp} from 'vue'
import {createPinia} from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
//element-ui
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
// 如果您正在使用CDN引入，请删除下面一行。
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
// if you just want to import css
import 'element-plus/theme-chalk/dark/css-vars.css'
import '@share/assets/main.css'
import '@share/assets/user-style.css'
import App from './App.vue'
import router from './router'
import {
    initCurrentSummonerInfo,
    initGameBaseData,
    initGameFLowInfo,
    initSystemInfo,
} from "@/renderer/main-window/utils/init.js";
import JsonViewer from 'vue-json-viewer'
import {initGameSession} from "@/renderer/main-window/utils/statusSync.js";
//element 的icon
const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

//内存数据管理
const pinia = createPinia();
pinia.use(piniaPluginPersistedstate);

app.use(pinia)
app.use(JsonViewer);
app.use(router)
app.use(ElementPlus)


async function load() {
    if (window.electron) {
        initGameSession();
        await init().catch(err => {
            console.error(`渲染进程加载基础数据异常:${err}`)
        })

        app.mount('#app');

    } else {
        setTimeout(() => {
            load();
            console.log("未检测到electron-api  等待加载中..")
        }, 50)
    }
}

async function init() {
    //系统信息
    await initSystemInfo();
    //游戏基础数据
    await initGameBaseData();
    //当前玩家的数据
    await initCurrentSummonerInfo();
    //当前房间/对局的数据
    await initGameFLowInfo();
}


await load();

//网页启动的时候主动拉取状态

//随后靠ws服务进行数据推送
//所有具体的状态管理靠网页端进行  后台服务只负责推送原始数据




